'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const db = uniCloud.database();
	const userCollection = db.collection('users');
	let userRes = await userCollection.where({"openId":event.openId}).get();
	//返回数据给客户端
	console.log('userRes._id : ', userRes)
	if(userRes.data && userRes.data.length>0){
		let uploadRes = await userCollection.doc(userRes.data[0]._id).update({
			adType:event.adType,
			adCode:event.adCode,
			isAdUser:true
		});
		console.log('uploadRes : ', JSON.stringify(uploadRes))
		return uploadRes;
	}else{
		return "false";
	}
	
	
};
